*WHAT'S ACROSS THE BORDER?
*JHA, NEUMARK, AND RODRIGUEZ-LOPEZ

include directories.do

foreach d in "emp" "wageap" {

* Load data at the czone-state-industry level
use "`datadir'`s'cbp_czone_state_20ind_sample.dta", clear

*Remove DC (starts in 2004)
drop if czone==11304 & state==11

*Keep restaurant industry
keep if wagerank90==1

egen czonestate=group(czone state)

* Generating variables 

gen mw=max_mw
gen lmw=log(mw)

*Generate totempm, which removes emp of the industry of interest
foreach b in "emp" {
gen tot`b'm=tot`b'-`b'
}

foreach b in "emp" "wageap" {

gen l`b'=log(`b')
gen ltot`b'=log(tot`b')
gen ltot`b'm=log(tot`b'm)
}

gen lworkagepop=log(workagepop)

**Generate YEAR DUMMIES 
qui tab year, gen(yeard)

 *Dummies region-year
qui tab region, gen(regiond)
gen regionyear=region*10000+year
qui tab regionyear, gen(regionyeard)

*State dummies
qui tab state, gen(stated)
gen trend=year-1989
forvalues z = 1/48 {
gen statedtrend`z'=stated`z'*trend
}

**************generating conditions and controls*************
local window1 "year>=1990 & year<=2016"

* Specify clustering

local options "vce(cluster state)"


* Specify outcome/regressor/instrument
local xvar "lmw"

* Specify controls
local year_controls yeard*
local regionyear_controls regionyeard*
local statetrend_controls statedtrend*

/* Regression specs */

local yvar "l`d'"
local czone_controls "ltot`d'm lworkagepop"


eststo m1_`d': reghdfe  `yvar' `xvar' `czone_controls'  if  (`window1') , `options' absorb(czonestate year)

eststo m2_`d': reghdfe  `yvar' `xvar' `czone_controls'  if  (`window1') , `options' absorb(czonestate regionyear)

eststo m3_`d': reghdfe  `yvar' `xvar' `czone_controls'  `statetrend_controls'  if  (`window1') , `options' absorb(czonestate regionyear)

eststo m4_`d': reghdfe  `yvar' `xvar' `czone_controls'  if  multi==1 & (`window1') , `options' absorb(czonestate year)

eststo m5_`d': reghdfe  `yvar' `xvar' `czone_controls'  if  multi==1 & (`window1') , `options' absorb(czonestate regionyear)

eststo m6_`d': reghdfe  `yvar' `xvar' `czone_controls'  `statetrend_controls'  if  multi==1 & (`window1') , `options' absorb(czonestate regionyear)

}

/* Print results */

tempfile specs

#delimit ;
esttab *_emp  using "`specs'.csv",
	nodepvars
	collabels(, none)
	mlabels(, none)
	b(%9.3f) se(%9.3f)
	star(* .10 ** .05 *** .01)
	title("Estimates for total employment")
	keep(`xvar' ltotempm lworkagepop)
	nonotes
	indicate("State trend controls = `statetrend_controls'")
	label
	stats(N, labels("N") fmt(0))	
	replace;
#delimit cr

#delimit ;
esttab *_wageap using "`specs'.csv",
	nodepvars
	collabels(, none)
	mlabels(, none)
	b(%9.3f) se(%9.3f)
	star(* .10 ** .05 *** .01)
	title("Estimates for earnings")
	keep(`xvar' ltotwageapm lworkagepop)
	nonotes
	indicate("State trend controls = `statetrend_controls'")
	label
	stats(N, labels("N") fmt(0))	
	append;
#delimit cr

* Switch the output to Excel format
insheet using "`specs'.csv", comma clear
export excel "`outdir'`s'TablesJNR.xlsx", sheetreplace sheet(Table2)








